<?php

ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);

if (isset($_POST['season']) && isset($_POST['selectedgame'])) {



$gamesheetfile = $_FILES['gamesheetfile'];
$gamesheetfilename = $_FILES['gamesheetfile']['name'];

$gamesheetfile_destination = './../../pdfs/' . $gamesheetfilename;

if (move_uploaded_file($gamesheetfile['tmp_name'], $gamesheetfile_destination)){
	echo "<center>Gamesheet Succesfully Uploaded</center>";
} else{
	echo "<center>Gamesheet not uploaded because of error #".$_FILES["gamesheetfile"]["error"] . "</center>";
};

$gamesheetfilenameNoExt = explode(".", $gamesheetfilename);

$youtubeID = $_POST['youtubeID'];

$comment = $_POST['comment'];
$selectedgame = $_POST['selectedgame'];
$season	 = $_POST['season'];

$sql = "UPDATE games 
SET comment = :comment, embed_code = '$youtubeID', nbbstatsfilename = '$gamesheetfilenameNoExt[0]'
WHERE gamenumber = '$selectedgame' 
AND season = '$season'";

try{    
	$dbpdo = new PDO('mysql:host=localhost;dbname=basketbal','cas','cas');
	$dbpdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $stmt = $dbpdo->prepare($sql);
	$stmt->bindParam(":comment", $comment, PDO::PARAM_STR);
	if (!$stmt->execute()) {
    echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
	} else {
	echo "<center> Game comment successfully updated </center>";
	}
} catch (PDOException $e) {
    
    $error = $e->getMessage();
}

}

?>